package cn.wolfcode.shop.seckillserver.web.controller.frontend;

import cn.wolfcode.shop.common.util.Result;
import cn.wolfcode.shop.seckillapi.service.ISeckillGoodService;
import cn.wolfcode.shop.seckillapi.vo.SeckillOrderVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/seckillGood")
public class SeckillGoodController {

    @Autowired
    private ISeckillGoodService seckillGoodService;


    /**
     * 提供秒杀商品列表
     * @return
     */
    @RequestMapping("/query")
    public Result<List<SeckillOrderVO>> query(){

        List<SeckillOrderVO> seckillOrderVOS = seckillGoodService.query();

        return Result.success(seckillOrderVOS);

    }

    /**
     * 根据 商品ID 提供对应的订单详情信息
     * @param goodId
     * @return
     */
    @RequestMapping("/find")
    public Result<SeckillOrderVO> find(@Param("goodId") Long goodId){

        SeckillOrderVO seckillOrderVO = seckillGoodService.findById(goodId);

        return Result.success(seckillOrderVO);

    }

    /**
     * Redis初始化商品数据
     * @return
     */
    @RequestMapping("/goodInit")
    public Result goodInit(){

        seckillGoodService.goodInit();
        return Result.success(null);

    }
}
